package cn.chenhongchao.zhaobiaopingtai.service.impl;

import cn.chenhongchao.zhaobiaopingtai.common.api.CommonPage;
import cn.chenhongchao.zhaobiaopingtai.dto.ReturnBidDTO;
import cn.chenhongchao.zhaobiaopingtai.entity.BusinessBid;
import cn.chenhongchao.zhaobiaopingtai.entity.WinBidApproval;
import cn.chenhongchao.zhaobiaopingtai.mapper.BusinessBidMapper;
import cn.chenhongchao.zhaobiaopingtai.mapper.TenderWinMapper;
import cn.chenhongchao.zhaobiaopingtai.service.TenderWinService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

@Service
public class TenderWinServiceImpl extends ServiceImpl<TenderWinMapper, WinBidApproval> implements TenderWinService {
    @Autowired
    private TenderWinMapper TenderWinMapper;



        @Override
        public CommonPage<WinBidApproval> dynamicQuery(Integer pageNum, Integer pageSize, ReturnBidDTO returnBidDTO) {

            QueryWrapper<WinBidApproval> wrapper = new QueryWrapper<>();

            // TODO tenderType 不知道对应哪个字段
//        if (!StringUtils.isEmpty(returnBidDTO.getTenderType())) {
//            wrapper.eq("commCode", returnBidDTO.getTenderType());
//        }1

            if (!StringUtils.isEmpty(returnBidDTO.getTenderNumber())) {
                wrapper.eq("tenderNumber", returnBidDTO.getTenderNumber());
            }

            if (!StringUtils.isEmpty(returnBidDTO.getTenderName())) {
                wrapper.like("tenderName", returnBidDTO.getTenderName());
            }

            if (!StringUtils.isEmpty(returnBidDTO.getCommCode())) {
                wrapper.like("commCode", returnBidDTO.getCommCode());
            }

            // 分页查询
            Page<WinBidApproval> page = new Page<>(pageNum, pageSize);
            TenderWinMapper.selectPage(page, wrapper);

            // 分装返回需要的类型
            CommonPage<WinBidApproval> returnBidCommonPage = new CommonPage<>();
            returnBidCommonPage.setList(page.getRecords());

            Long pages = page.getPages();
            Integer total = Integer.valueOf(pages.toString());
            returnBidCommonPage.setTotalPage(total);

            returnBidCommonPage.setPageSize(pageSize);

//        Long current = page.getCurrent();
//        Integer num = Integer.valueOf(current.toString());
            returnBidCommonPage.setPageNum(pageNum);
            returnBidCommonPage.setTotal(page.getTotal());

            return returnBidCommonPage;
        }

}
